//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.controller.manage;

import com.xw.model.DicGroupLimit;
import com.xw.service.OrdersService;
import com.xw.service.VideosService;
import com.xw.service.sysconfig.DicGroupLimitService;
import com.xw.util.PropertiesUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 *
 */
@Controller
@RequestMapping("/manage/orders/")
@Scope("prototype")
public class OrdersController {
    @Resource
    private VideosService videosService;
    @Resource
    private DicGroupLimitService groupLimitService;
    @Resource
    private OrdersService ordersService;


    /**
     * 根据userId查询自己发布的已售出的订单
     * @param userId
     * @return
     */
    @RequestMapping(value = "findOrdersByPublishUserId",method = RequestMethod.GET)
    @ResponseBody
    public Object findOrdersByPublishUserId(String userId,Integer page, Integer limit){
        Map map = ordersService.findOrdersByPublishUserId(userId, page, limit);
        return map;
    }

    /**
     * 删除
     * @return
     */
    @RequestMapping(value = "del",method = RequestMethod.POST)
    @ResponseBody
    public Map del(String videoId){
        Map map =videosService.del(videoId);
        return map;
    }

    /**
     * 跳转到商品分类列表页面
     * @return
     */
    @RequestMapping(value = "findAll",method = RequestMethod.GET)
    public String findAll(HttpServletRequest request, String glId){
        //查询该子导航的增删改查的权限
        DicGroupLimit model = groupLimitService.queryByUUID(glId);
        request.setAttribute("model",model);
        request.setAttribute("url", PropertiesUtil.getProperty("URL"));
        return "orders/list";
    }

    /**
     * 获取列表数据
     * @return
     */
    @RequestMapping(value = "findAllJson",method = RequestMethod.GET)
    @ResponseBody
    public Object findAllJson(Integer page,Integer limit,String date,Integer ordersStatus,String videoName,String teacherName){
        Map map = ordersService.findByWhere(page,limit,date,ordersStatus,videoName,teacherName);
        return map;
    }
}
